package com.twu.biblioteca;

/**
 * Created by siba on 23/09/14.
 */

public class BookInformation {

    private static Book [] libraryBooks;

    public static Book [] getLibraryBooks(){
        return libraryBooks;
    }

    //This is a stub method until a database is used
    public static Book [] fetchBookDetails(){
        Book books [] = new Book[4];
        books[0] = new Book();
        books[0].setAuthor("Dan Brown");
        books[0].setTitle("Deception Point");
        books[0].setYearPublished("2001");
        books[0].setIsCheckedOut(false);

        books[1] = new Book();
        books[1].setAuthor("Kathy Sierra");
        books[1].setTitle("Head First Java");
        books[1].setYearPublished("2005");
        books[1].setIsCheckedOut(false);

        books[2] = new Book();
        books[2].setAuthor("Khaled Hosseini");
        books[2].setTitle("And the Mountains Echoed");
        books[2].setYearPublished("2013");
        books[2].setIsCheckedOut(false);

        books[3] = new Book();
        books[3].setAuthor("John Gray");
        books[3].setTitle("Men Are from Mars, Women Are from Venus");
        books[3].setYearPublished("1992");
        books[3].setIsCheckedOut(false);

        return books;
    }

    public static void toggleBookCheckedOutInfo(Book libraryBook) {
        for (int count = 0; count < libraryBooks.length; count++) {
            if (libraryBook.getTitle().equalsIgnoreCase(libraryBooks[count].getTitle()) &&
                    libraryBook.getAuthor().equalsIgnoreCase(libraryBooks[count].getAuthor()) &&
                    libraryBook.getYearPublished().equalsIgnoreCase(libraryBooks[count].getYearPublished())) {
                libraryBooks[count].setIsCheckedOut(!libraryBooks[count].getIsCheckedOut());
                break;
            }
        }

    }

    public static void init() {
        libraryBooks = fetchBookDetails();
    }
}
